<template>
  <div>
    <section class="main">
      <input v-model="isAll" id="toggle-all" class="toggle-all" type="checkbox" />
      <label for="toggle-all">Mark all as complete</label>
      <ul class="todo-list" >
        <!-- 当任务已完成，可以给 li 加上 completed 类，会让元素加上删除线 -->
        <li v-for="(item,index) in list" :key="index" :class="{completed:item.isDone}">
          <div class="view">
            <input class="toggle" @change="hChange(item.id)" type="checkbox" :checked="item.isDone" />
            <label>{{item.name}}</label>
            <button @click="del(item.id)" class="destroy"></button>
          </div>
        </li>
      </ul>
    </section>
  </div>
</template>

<script>
export default {
  name: "VueDemoTodoMain",
  props:{
    list:{
      type:Array,
      required:true
    }
  },

  data() {
    return {};
  },
  methods: {
    del(id){
      //1.绑定点击事件传入id
      //2.将id子传父递给App组件
       this.$emit("shan", id);
    },
    hChange(id){
      //修改状态
      //绑定change事件,传入id
      //将id传递给父组件
      this.$emit('changeDone',id)
    }
  },
  computed:{
    isAll:{
      get(){
        return this.list.every(item=>item.isDone)
      },
      set(val){
        //当用户修改状态触发
        this.$emit('changeAll', val);
      }
    }
  }
};
</script>

<style lang="scss" scoped>
</style>